package com.peng.controller;

import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import com.peng.apis.PayFeignApi;
import com.peng.entities.PayDTO;
import com.peng.result.ResultData;
import jakarta.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.http.HttpEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

import java.io.IOException;
import java.util.List;

@RestController
public class OrderController {
    public static final String url="http://cloud-pay-service";

    @Resource
    private RestTemplate restTemplate;

    @Resource
    private PayFeignApi payFeignApi;

    @GetMapping("/consumer/pay/get/all")
    public ResultData getPayAllInfo(){
        return payFeignApi.getOrders();
    }

    @PostMapping("/consumer/pay/add")
    public ResultData addOrder(PayDTO payDTO) {
        //参数一：  调用的URL接口地址
        //参数二：  传递的参数
        //参数三：  返回类型.class
        return restTemplate.postForObject(url+"/pay/add", payDTO, ResultData.class);
    }
    @GetMapping("/consumer/pay/get/{id}")
    public ResultData getPayInfo(@PathVariable("id") Integer id) throws IOException {

        //使用RestTemplate进行接口服务调用
        //参数一：  调用的URL接口地址
        //参数二：  返回类型.class
        //参数三：  路径变量
        //return restTemplate.getForObject(url+"/pay/get/"+id, ResultData.class, id);

        //使用Feign进行接口服务调用
        return payFeignApi.getOrder(id);
    }



}
